﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace uzing
{
    public class uzCSharedMemory
    {
        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern IntPtr _inklude_createInstance();

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern bool _inklude_createMemory(IntPtr pMem, [MarshalAs(UnmanagedType.LPWStr)]string memName, uint memSize);

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern bool _inklude_readMemory(IntPtr pMem, byte[] buffer, uint readSize, uint offSet);

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern bool _inklude_writeMemory(IntPtr pMem, byte[] buffer, uint wroteSoze, uint offSet);

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern bool _isNewlyWritten(IntPtr pMem);

        private IntPtr pMemory;

        public uzCSharedMemory(ref string MemoryName, uint MemorySize)
        {
            pMemory = _inklude_createInstance();
            _inklude_createMemory(pMemory, MemoryName, MemorySize);
        }

        public bool ReadMemory(byte[] Buffer, uint ReadSize, uint OffSet)
        {
            return _inklude_readMemory(pMemory, Buffer, ReadSize, OffSet);
        }

        public bool WriteMemory(byte[] Buffer, uint WriteSize, uint OffSet)
        {
            return _inklude_writeMemory(pMemory, Buffer, WriteSize, OffSet);
        }

        public bool IsNewlyWritten()
        {
            return _isNewlyWritten(pMemory);
        }
    }
}
